/*******************************************************************
 * 外语翻译平台(translate) 
 *
 * 成都一亿信息技术公司 版权所有
 * 
 * Copyright (C) 2010 Transer Information Technology Co., Ltd.
 *
 * @Version : 1.0  2011-1-4 下午03:09:07
 *
 * TranserSearchAction.java
 *
 *******************************************************************/
package com.transer.web.action.search;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.transer.constant.Constants;
import com.transer.constant.SQLConstants;
import com.transer.persistance.dao.IUserDao;
import com.transer.utils.StringTools;
import com.transer.utils.Utils;
import com.transer.web.action.JsonActionSupport;
import com.transer.web.page.TranserPageData;

/**
 * class defination are there
 * 
 * @author Mark
 * 
 * @version 1.0 ywengineer@gmail.com
 * 
 */
public class TranserSearchAction extends JsonActionSupport {
	private static final long serialVersionUID = 5370848639581526086L;
	/** 用户操作 */
	private IUserDao userDao;
	/** 搜索内容 */
	private String searchTxt;
	/** 用户类型 */
	private String userType;
	/** 源语言 */
	private String langFrom;
	/** 目标语言 */
	private String langTo;
	/** 擅长领域 */
	private String goodAtArea;
	/** 擅长类型 */
	private String goodAt;
	/** 是否上传证书 */
	private String certified;
	/** 城市 */
	private String city;
	/** 省份 */
	private String province;
	/** 翻译等级 */
	private String experience;
	/** 当前页面 */
	private int page;
	/** 总页数 */
	private int totalPage;
	/** 当前页面数据 */
	private List<TranserPageData> pageData;

	/*
	 * (non-Javadoc)
	 * 
	 * 评级
	 * 
	 * 初级 0-2
	 * 
	 * 中级 3-6
	 * 
	 * 高级 7-10
	 * 
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	@Override
	public String execute() throws Exception {
		// 查询参数
		Map<String, Object> params = new HashMap<String, Object>();
		// 用户类型(整数)
		int type = Utils.getInteger(userType);
		// 判断
		type = type == 0 ? 1 : type;

		params.put(SQLConstants.USER_SEARCH_CERTIFICATE, Utils.getBoolean(certified));
		params.put(SQLConstants.USER_SEARCH_CITY, Utils.getInteger(city));
		params.put(SQLConstants.USER_SEARCH_EXPERICE, Utils.getInteger(experience));
		params.put(SQLConstants.USER_SEARCH_GOOD_AT_AREA, goodAtArea);
		params.put(SQLConstants.USER_SEARCH_GOOD_AT, StringTools.toIntegerArray(goodAt, ","));
		params.put(SQLConstants.USER_SEARCH_LANG_FROM, StringTools.toIntegerArray(langFrom, ","));
		params.put(SQLConstants.USER_SEARCH_LANG_TO, StringTools.toIntegerArray(langTo, ","));
		params.put(SQLConstants.USER_SEARCH_PROVINCE, Utils.getInteger(province));
		params.put(SQLConstants.USER_SEARCH_TYPE, type);
		// 结果集数量
		int size = userDao.findUserSize(params);
		// 总页面数量
		totalPage = new BigDecimal(size).divide(new BigDecimal(Constants.TRANSER_PAGE_SIZE), RoundingMode.UP).intValue();
		// 如果比第一页数量小
		if (page <= 0) {
			page = 1;
		} else if (page > totalPage) {// 超过最后一页
			page = totalPage;
		}
		// 忽略条目数
		int skip = (page - 1) * Constants.TRANSER_PAGE_SIZE;
		// 获取数量
		pageData = userDao.findUsers(params, skip, Constants.TRANSER_PAGE_SIZE);
		// 返回成功
		return TranserSearchAction.SUCCESS;
	}

	/**
	 * @return the searchTxt
	 */
	public String getSearchTxt() {
		return searchTxt;
	}

	/**
	 * @param searchTxt
	 *            the searchTxt to set
	 */
	public void setSearchTxt(String searchTxt) {
		this.searchTxt = searchTxt;
	}

	/**
	 * @return the langFrom
	 */
	public String getLangFrom() {
		return langFrom;
	}

	/**
	 * @param langFrom
	 *            the langFrom to set
	 */
	public void setLangFrom(String langFrom) {
		this.langFrom = langFrom;
	}

	/**
	 * @return the langTo
	 */
	public String getLangTo() {
		return langTo;
	}

	/**
	 * @param langTo
	 *            the langTo to set
	 */
	public void setLangTo(String langTo) {
		this.langTo = langTo;
	}

	/**
	 * @return the certified
	 */
	public String isCertified() {
		return certified;
	}

	/**
	 * @param certified
	 *            the certified to set
	 */
	public void setCertified(String certified) {
		this.certified = certified;
	}

	/**
	 * @return the city
	 */
	public String getCity() {
		return city;
	}

	/**
	 * @param city
	 *            the city to set
	 */
	public void setCity(String city) {
		this.city = city;
	}

	/**
	 * @return the province
	 */
	public String getProvince() {
		return province;
	}

	/**
	 * @param province
	 *            the province to set
	 */
	public void setProvince(String province) {
		this.province = province;
	}

	/**
	 * @return the experience
	 */
	public String getExperience() {
		return experience;
	}

	/**
	 * @param experience
	 *            the experience to set
	 */
	public void setExperience(String experience) {
		this.experience = experience;
	}

	/**
	 * @return the page
	 */
	public int getPage() {
		return page;
	}

	/**
	 * @param page
	 *            the page to set
	 */
	public void setPage(int page) {
		this.page = page;
	}

	/**
	 * @return the userDao
	 */
	public IUserDao getUserDao() {
		return userDao;
	}

	/**
	 * @param userDao
	 *            the userDao to set
	 */
	public void setUserDao(IUserDao userDao) {
		this.userDao = userDao;
	}

	/**
	 * @return the pageData
	 */
	public List<TranserPageData> getPageData() {
		return pageData;
	}

	/**
	 * @param pageData
	 *            the pageData to set
	 */
	public void setPageData(List<TranserPageData> pageData) {
		this.pageData = pageData;
	}

	/**
	 * @return the totalPage
	 */
	public int getTotalPage() {
		return totalPage;
	}

	/**
	 * @param totalPage
	 *            the totalPage to set
	 */
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	/**
	 * @return the goodAtArea
	 */
	public String getGoodAtArea() {
		return goodAtArea;
	}

	/**
	 * @param goodAtArea
	 *            the goodAtArea to set
	 */
	public void setGoodAtArea(String goodAtArea) {
		this.goodAtArea = goodAtArea;
	}

	/**
	 * @return the userType
	 */
	public String getUserType() {
		return userType;
	}

	/**
	 * @param userType
	 *            the userType to set
	 */
	public void setUserType(String userType) {
		this.userType = userType;
	}

	/**
	 * @return the goodAt
	 */
	public String getGoodAt() {
		return goodAt;
	}

	/**
	 * @param goodAt
	 *            the goodAt to set
	 */
	public void setGoodAt(String goodAt) {
		this.goodAt = goodAt;
	}

	/**
	 * @return the certified
	 */
	public String getCertified() {
		return certified;
	}

}